<template>
  <div class="play-list">
    <div class="play-list-top">
      <div class="left">
        <img src="../assets/play.png" alt="">
        <div class="title">播放全部</div>
        <div class="num">(共{{playlist.tracks.length}}首)</div>
      </div>
      <div class="btn">
        + 收藏 ({{ parseInt(playlist.subscribedCount/100)/100 }}万)
      </div>
    </div>
    <!-- 歌曲列表 -->
    <div class="song-list">
      <div class="song-item" v-for="(item,index) in playlist.tracks" :key="item.id">
        <div class="left" @click="play(item.id)">
          <div class="index">{{index+1}}</div>
          <div class="content">
            <div class="title">{{item.name}}</div>
            <div class="author">
              <span class="tag" v-for="(tag, index) in playlist.tags" :key="index">{{tag}}</span>
              <span>{{item.al.name}}</span>
            </div>
          </div>
        </div>
        <div class="right">
          <img src="../assets/mv.png" alt="" v-if="item.mv">
          <img src="../assets/more.png" alt="">
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { toRefs } from 'vue'
import { useStore } from 'vuex'
export default {
  props: ['playlist'],
  setup(props) {
    const { playlist } = toRefs(props)
    const store = useStore()
    store.commit('setPlayList', playlist)
    // console.log(playlist)

    const play = id => {
      store.commit('setSongId', id)
    }

    return {
      playlist,
      play
    }
  }
}
</script>

<style lang="less" scoped>
.play-list {
  width: 7.5rem;
  background-color: #fff;
  margin-top: 0.4rem;
  padding: 0 0.3rem;
  border-radius: 0.3rem;
  .play-list-top {
    height: 0.8rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .left {
      display: flex;
      align-items: center;
      img {
        width: 0.4rem;
        height: 0.4rem;
      }
      .title {
        margin-left: 0.3rem;
        font-size: 0.35rem;
        font-weight: 900;
      }
      .num {
        font-size: 0.3rem;
        color: #ccc;
      }
    }
    .btn {
      font-size: 0.33rem;
      background-color: orangered;
      padding: 0.1rem;
      border-radius: 0.4rem;
    }
  }

  .song-list {
    margin-bottom: 1.2rem;
    .song-item {
      display: flex;
      justify-content: space-between;
      align-items: center;
      height: 1.2rem;
      margin-top: 0.15rem;
      .left {
        display: flex;
        align-items: center;
        .content {
          margin-left: 0.4rem;
          width: 4.8rem;
          .author {
            // height: 1rem;
            font-size: 0.2rem;
            margin-top: 0.1rem;
            color: #666;
          }
        }
        .title,
        .index {
          font-size: 0.4rem;
          word-break: keep-all;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
        .tag {
          font-size: 0.2rem;
          margin-right: 0.05rem;
          color: orangered;
          border: 1px solid orangered;
        }
      }
      .right {
        img {
          width: 0.6rem;
          height: 0.6rem;
        }
      }
    }
  }
}
</style>